package com.evenmo.test;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.evenmo.mapper.ClazzMapper;
import com.evenmo.mapper.StudentMapper;
import com.evenmo.pojo.Clazz;
import com.evenmo.pojo.Student;
import com.evenmo.util.MySqlSessionFactory;

public class MybatisTest1 {

	private SqlSession session;

	private ClazzMapper clazzDao;
	private StudentMapper studentDao;
	private Clazz clazz;
	private Student student;
	@Before
	public void initDatas() {
		session = getSqlSession();
		clazzDao=session.getMapper(ClazzMapper.class);
		studentDao = session.getMapper(StudentMapper.class);
		clazz=new Clazz();
		student=new Student();
	}

	@After
	public void afterThings() {
		session.commit();
	
		session.close();
	}

	@Test
	public void queryClazzOfStudentsByClazzId() {
		Clazz c = clazzDao.queryClazzOfStudentsByClazzId(1);
		System.out.println(c);
	}

	
	@Test
	public void queryStudentsByClazzId(){
		List<Student> students = studentDao.queryStudentsByClazzId(1);
		students.forEach(s->System.out.println(s));
	}
	
	@Test
	public void queryByStudentId(){
		Student s = studentDao.queryByStudentId(1);
		System.out.println(s);
	}
	public static SqlSession getSqlSession() {
		return MySqlSessionFactory.getSqlSession();
	}

}
